﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;

using EasyAR;
using EasyAR.Model;

namespace EasyARDDemo
{
    public partial class MainPage : UserControl
    {
        ARServices arServices = new ARServices();

        public MainPage()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            CameraModel cameraModel = new CameraModel();
            cameraModel.InitializeCameraAsDefault();
            arServices.AddCameraModel(cameraModel, VideoArea);
            arServices.AddViewContainer(ViewPortContainer);
            Stream marker1 = Application.GetResourceStream(new Uri("EasyARDDemo;component/markers/patt006.pat", UriKind.Relative)).Stream;
            Stream marker2 = Application.GetResourceStream(new Uri("EasyARDDemo;component/markers/patt012.pat", UriKind.Relative)).Stream;
            arServices.AddMarkerAndSLControl(marker1, "Pattern06", 8, 8, 40.0, textBox1);
            arServices.AddMarkerAndSLControl(marker2, "Pattern12", 8, 8, 40.0, button1);
            arServices.InitializeARSilverlight(1, 4000);

            arServices.ARSLModel.BeforeItemDetected += new ARSilverlightModel.BeforeItemDetectedEventHandler((element) =>
            {
                element.Opacity = 0;
            });

            arServices.ARSLModel.AfterItemDetected += new ARSilverlightModel.AfterItemDetectedEventHandler((element) =>
            {
                element.Opacity = 0.7;
            });
        }

        private void btStart_Click(object sender, RoutedEventArgs e)
        {
            arServices.StartAR();
        }
    }
}
